package controllers.report;

import action.BeforeAfterAction;

import com.fasterxml.jackson.databind.node.ObjectNode;

import play.mvc.*;
import play.libs.Json;
import service.Paging;
import service.Utils;
import models.report.User;

@With(BeforeAfterAction.class)
public class UserController extends Controller {
	
    public static Result index() {
        return ok(views.html.report.user.index.render());
    }
    
    @BodyParser.Of(BodyParser.Json.class)
    public static Result search() {
    	String type 	= request().getQueryString("type");
    	Integer startTime = Utils.parseToDateKey(request().getQueryString("startTime"));
    	Integer endTime = Utils.parseToDateKey(request().getQueryString("endTime"));
    	
        Paging paging = User.search(type, startTime, endTime);
         
    	ObjectNode dataJson = Json.newObject();
    	dataJson.put("total", paging.totalRow);
    	dataJson.put("list", Json.toJson(paging.dataList));
    	
        return ok(dataJson);
    }
}
